feat: view human-readable database size and v2 route for DBsize#130
feat: view human-readable database size and v2 route for DBsize#130williamrusdyputra merged 1 commit intomainfrom
Conversation
Change the action route for `getDatabaseSize()` to v2 route and adds `getDatabaseSizePretty()` method to the Action class, enabling clients to retrieve database size in a user-friendly format (e.g., "22 GB", "1.5 TB") instead of raw byte counts. This complements the existing `getDatabaseSize()` method by providing a more accessible view of database storage metrics for end users and dashboards. resolves: trufnetwork/truf-network#1219
WalkthroughUpdates the Action class to use the v2 database size endpoint and adds a new method to fetch a human-readable size. Corresponding integration test added to validate the pretty-printed size format. No other files changed. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Client
participant A as Action
participant S as Contracts API
rect rgba(200,220,255,0.25)
note over C,A: Get raw database size (v2)
C->>A: getDatabaseSize()
A->>S: call "get_database_size_v2"
S-->>A: rows[{ database_size }]
A-->>C: number (database_size)
end
rect rgba(220,255,220,0.25)
note over C,A: Get pretty database size (new)
C->>A: getDatabaseSizePretty()
A->>S: call "get_database_size_v2_pretty"
S-->>A: rows[{ database_size_pretty }]
A-->>C: string (e.g., "123 MB")
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Time Submission Status
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/integration/databaseSize.test.ts (1)
26-37: Consider improving regex pattern strictness and test independence.The test structure is solid and follows the established pattern. Two minor observations:
- Regex pattern: The current pattern
/\d+.*\s*(bytes|kB|MB|GB|TB)/iis permissive and could match invalid formats like "123abc GB". Consider a stricter pattern:- expect(databaseSizePretty).toMatch(/\d+.*\s*(bytes|kB|MB|GB|TB)/i) + expect(databaseSizePretty).toMatch(/^\d+(\.\d+)?\s+(bytes|kB|MB|GB|TB|PB)$/i)This ensures the format is exactly:
number[.decimal] unit(e.g., "22 GB", "1.5 TB")
- Test independence: This test relies on the database having data from the first test (which deploys streams). While
describe.sequentialensures order, the test would be more robust if it explicitly deployed streams or documented this dependency.However, if the backend format might vary or include additional text, the lenient regex may be intentional to avoid test brittleness, in which case the current implementation is acceptable.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/contracts-api/action.ts(2 hunks)tests/integration/databaseSize.test.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/integration/databaseSize.test.ts (1)
tests/integration/utils.ts (1)
testWithDefaultWallet(9-11)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: test
🔇 Additional comments (2)
src/contracts-api/action.ts (2)
949-957: Ensure the pretty-size endpoint exists and handle empty responses• Confirm the
get_database_size_v2_prettyendpoint is implemented and deployed on the backend.
• Add a guard for emptyrowsto throw a clear, descriptive error (e.g."No database size data returned").
939-947: Ensureget_database_size_v2endpoint exists and returns{ database_size: BigInt }[]
I couldn’t find an implementation for this RPC in the repo; please verify the backend exposes it and maintains the expected response schema.
Change the action route for
getDatabaseSize()to v2 route and addsgetDatabaseSizePretty()method to the Action class, enabling clients to retrieve database size in a user-friendly format (e.g., "22 GB", "1.5 TB") instead of raw byte counts.This complements the existing
getDatabaseSize()method by providing a more accessible view of database storage metrics for end users and dashboards.resolves: https://github.com/trufnetwork/truf-network/issues/1219
related file: https://github.com/trufnetwork/node/blob/main/internal/migrations/024-get-database-size-v2.sql
Summary by CodeRabbit
New Features
Tests